﻿using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_DLL.Product.database;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_RORZE_PRODUCT.Product.DAO
{
    public class ClsIncauhinhDAO : ExecuteSQL
    {
        ExecuteSQL Execute = new ExecuteSQL();

        //Loại cấu hình
        public DataTable GetAllConfigure()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigure.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public void InsertConfigure(string Name)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsConfigureSP.ConfigureID, SqlDbType.NVarChar,Name)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigure.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateConfigure(string ID, string Name)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsConfigureSP.ConfigureID, SqlDbType.NVarChar,ID),
                    CreateParameter(clsConstantsSP.ClsConfigureSP.ConfigureIDmoi, SqlDbType.NVarChar,Name)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionConfigure.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteConfigure(string ID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsConfigureSP.ConfigureID, SqlDbType.NVarChar, ID)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionConfigure.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Phôi chuẩn của phòng KD

        public DataTable GetAllPCPKD()
        {
            string sql = clsConstantsFuction.ClsFuctionPCPKD.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public void InsertPCPKD(string Ptype)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPCPKDSP.PType, SqlDbType.NVarChar, Ptype)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionPCPKD.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdatePCPKD(string Ptype, string ID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPCPKDSP.ID, SqlDbType.NVarChar, ID),
                    CreateParameter(clsConstantsSP.ClsPCPKDSP.PType, SqlDbType.NVarChar, Ptype)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionPCPKD.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeletePCKD(string ID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsPCPKDSP.PType, SqlDbType.NVarChar, ID)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionPCPKD.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Hình dạng vật liệu

        public DataTable GetAllMaterialForm()
        {
            string sql = clsConstantsFuction.ClsFuctionMaterialForm.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }
        public void InsertMaterialForm(string Name)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialFormSP.MaterialFormID, SqlDbType.NVarChar, Name)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionMaterialForm.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void UpdateMaterialForm(string Name, string ID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialFormSP.ID, SqlDbType.NVarChar, ID),
                    CreateParameter(clsConstantsSP.ClsMaterialFormSP.MaterialFormID, SqlDbType.NVarChar, Name)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionMaterialForm.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public void DeleteMaterialForm(string ID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter(clsConstantsSP.ClsMaterialFormSP.ID, SqlDbType.NVarChar, ID)
                };
                Execute.DoDelete(clsConstantsFuction.ClsFuctionMaterialForm.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Kí hiệu chi tiết

        public DataTable GetAllKHCT()
        {
            string sql = clsConstantsFuction.ClsFuctionKHChiTiet.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertKHCT(string KH, string TenKH, string MaKH)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH),
                    CreateParameter("@TenKH", SqlDbType.NVarChar, TenKH),
                    CreateParameter("@MaKH", SqlDbType.NVarChar, MaKH)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionKHChiTiet.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateKHCT(string KH, string TenKH, string MaKH)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH),
                    CreateParameter("@TenKH", SqlDbType.NVarChar, TenKH),
                    CreateParameter("@MaKH", SqlDbType.NVarChar, MaKH)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionKHChiTiet.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteKHCT(string KH)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH)
                };
                Execute.DoUpdate(clsConstantsFuction.ClsFuctionKHChiTiet.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        public DataTable GetAllCustomer()
        {
            string sql = clsConstBasicListFuction.ClsCustomerFuction.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        //Loại vật liệu
        public DataTable GetAllLVL()
        {
            string sql = clsConstantsFuction.ClsFuctionLVL.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertLVL(string KH, string TryTrong)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH),
                    CreateParameter("@TyTrong", SqlDbType.NVarChar, TryTrong)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionLVL.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateLVL(string KH, string TryTrong)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH),
                    CreateParameter("@TyTrong", SqlDbType.NVarChar, TryTrong)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionLVL.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteLVL(string KH)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@KH", SqlDbType.NVarChar, KH)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionLVL.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //ResionList
        public DataTable GetAllRession()
        {
            string sql = clsConstantsFuction.ClsFuctionRession.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertRession(string RessionID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RessionID", SqlDbType.NVarChar, RessionID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRession.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateRession(string RessionID, string RessionIDcu)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RessionID", SqlDbType.NVarChar, RessionID),
                    CreateParameter("@RessionIDcu", SqlDbType.NVarChar, RessionIDcu)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRession.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteRession(string RessionID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RessionID", SqlDbType.NVarChar, RessionID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRession.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Require list

        public DataTable GetAllRequire()
        {
            string sql = clsConstantsFuction.ClsFuctionRequire.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertRequire(string RequireID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RequireID", SqlDbType.NVarChar, RequireID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRequire.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateRequire(string RequireID, string RequireIDcu)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RequireID", SqlDbType.NVarChar, RequireID),
                    CreateParameter("@RequireIDcu", SqlDbType.NVarChar, RequireIDcu)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRequire.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteRequire(string RequireID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@RequireID", SqlDbType.NVarChar, RequireID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionRequire.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        //Shape List

        public DataTable GetAllShape()
        {
            string sql = clsConstantsFuction.ClsFuctionShape.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertShape(string ShapeID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ShapeID", SqlDbType.NVarChar, ShapeID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionShape.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateShape(string ShapeID,string ShapeIDcu)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ShapeID", SqlDbType.NVarChar, ShapeID),
                    CreateParameter("@ShapeIDcu", SqlDbType.NVarChar, ShapeIDcu)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionShape.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteShape(string ShapeID)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ShapeID", SqlDbType.NVarChar, ShapeID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionShape.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        // Get MaterialType
        public DataTable GetMaterial(string ID)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.NVarChar, ID)
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionConfigureData.GetMaterial, parameter, true);


        }
        //ConfigureData

        public DataTable GetAllConfigureData()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.GetAll;
            return Execute.DoStoreProcedure(sql, true);
        }

        public void InsertConfigureData(ConfigureData b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@Page", SqlDbType.Int, b.Page),
                    CreateParameter("@Bafu", SqlDbType.Bit, b.Bafu),
                    CreateParameter("@BAnod", SqlDbType.Bit, b.BAnod),
                    CreateParameter("@Blast30", SqlDbType.Bit, b.Blast30),
                    CreateParameter("@Blast60", SqlDbType.Bit, b.Blast60),
                    CreateParameter("@Casiras", SqlDbType.Bit, b.Casiras),
                    CreateParameter("@ConfigureID", SqlDbType.NVarChar, b.ConfigureID),
                    CreateParameter("@Date", SqlDbType.DateTime, b.Date),
                    CreateParameter("@HairLine", SqlDbType.Bit, b.HairLine),
                    CreateParameter("@Helisart", SqlDbType.Bit, b.Helisart),
                    CreateParameter("@InLuoi", SqlDbType.Bit, b.InLuoi),
                    CreateParameter("@KDID", SqlDbType.NVarChar, b.KDID),
                    CreateParameter("@Length", SqlDbType.Float, b.Length),
                    CreateParameter("@MaBong", SqlDbType.Bit, b.MaBong),
                    CreateParameter("@MaterialID", SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter("@Migaky", SqlDbType.Bit, b.Migaky),
                    CreateParameter("@Note", SqlDbType.NVarChar, b.Note),
                    CreateParameter("@Number", SqlDbType.Int, b.Number),
                    CreateParameter("@Outsite", SqlDbType.Bit, b.Outsite),
                    CreateParameter("@Pack", SqlDbType.Bit, b.Pack),
                    CreateParameter("@PalCoat", SqlDbType.Bit, b.PalCoat),
                    CreateParameter("@PartNo", SqlDbType.NVarChar, b.PartNo),
                    CreateParameter("@RequireID", SqlDbType.NVarChar, b.RequireID),
                    CreateParameter("@RessionID", SqlDbType.NVarChar, b.RessionID),
                    CreateParameter("@Seal", SqlDbType.Bit, b.Seal),
                    CreateParameter("@SerialClose", SqlDbType.Bit, b.SerialClose),
                    CreateParameter("@ShapeID", SqlDbType.NVarChar, b.ShapeID),
                    CreateParameter("@StaffID", SqlDbType.NVarChar, b.StaffID),
                    CreateParameter("@SWash", SqlDbType.Bit, b.SWash),
                    CreateParameter("@Thickness", SqlDbType.Float, b.Thickness),
                    CreateParameter("@WAnod", SqlDbType.Bit, b.WAnod),
                    CreateParameter("@Width", SqlDbType.NVarChar, b.Width),
                    CreateParameter("@Heru", SqlDbType.Bit, b.Heru),
                    CreateParameter("@Niken", SqlDbType.Bit, b.Niken),
                    CreateParameter("@MaiBongDP", SqlDbType.Bit, b.MaiBongDP),
                    CreateParameter("@RM",SqlDbType.Bit,b.RM)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigureData.Insert, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void UpdateConfigureData(ConfigureData b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.Int, b.ID),

                    CreateParameter("@Page", SqlDbType.Int, b.Page),
                    CreateParameter("@Bafu", SqlDbType.Bit, b.Bafu),
                    CreateParameter("@BAnod", SqlDbType.Bit, b.BAnod),
                    CreateParameter("@Blast30", SqlDbType.Bit, b.Blast30),
                    CreateParameter("@Blast60", SqlDbType.Bit, b.Blast60),
                    CreateParameter("@Casiras", SqlDbType.Bit, b.Casiras),
                    CreateParameter("@ConfigureID", SqlDbType.NVarChar, b.ConfigureID),
                    CreateParameter("@Date", SqlDbType.DateTime, b.Date),
                    CreateParameter("@HairLine", SqlDbType.Bit, b.HairLine),
                    CreateParameter("@Helisart", SqlDbType.Bit, b.Helisart),
                    CreateParameter("@InLuoi", SqlDbType.Bit, b.InLuoi),
                    CreateParameter("@KDID", SqlDbType.NVarChar, b.KDID),
                    CreateParameter("@Length", SqlDbType.NVarChar, b.Length),
                    CreateParameter("@MaBong", SqlDbType.Bit, b.MaBong),
                    CreateParameter("@MaterialID", SqlDbType.NVarChar, b.MaterialID),
                    CreateParameter("@Migaky", SqlDbType.Bit, b.Migaky),
                    CreateParameter("@Note", SqlDbType.NVarChar, b.Note),
                    CreateParameter("@Number", SqlDbType.Int, b.Number),
                    CreateParameter("@Outsite", SqlDbType.Bit, b.Outsite),
                    CreateParameter("@Pack", SqlDbType.Bit, b.Pack),
                    CreateParameter("@PalCoat", SqlDbType.Bit, b.PalCoat),
                    CreateParameter("@PartNo", SqlDbType.NVarChar, b.PartNo),
                    CreateParameter("@RequireID", SqlDbType.NVarChar, b.RequireID),
                    CreateParameter("@RessionID", SqlDbType.NVarChar, b.RessionID),
                    CreateParameter("@Seal", SqlDbType.Bit, b.Seal),
                    CreateParameter("@SerialClose", SqlDbType.Bit, b.SerialClose),
                    CreateParameter("@ShapeID", SqlDbType.NVarChar, b.ShapeID),
                    CreateParameter("@StaffID", SqlDbType.NVarChar, b.StaffID),
                    CreateParameter("@SWash", SqlDbType.Bit, b.SWash),
                    CreateParameter("@Thickness", SqlDbType.Float, b.Thickness),
                    CreateParameter("@WAnod", SqlDbType.Bit, b.WAnod),
                    CreateParameter("@Width", SqlDbType.NVarChar, b.Width),
                    CreateParameter("@Heru", SqlDbType.Bit, b.Heru),
                    CreateParameter("@Niken", SqlDbType.Bit, b.Niken),
                    CreateParameter("@MaiBongDP", SqlDbType.Bit, b.MaiBongDP),
                    CreateParameter("@RM",SqlDbType.Bit, b.RM)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigureData.Update, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void DeleteConfigureData(ConfigureData b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.Int, b.ID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigureData.Delete, parameter, true);

            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public DataTable GetAllConfigureDataByID(ConfigureData b)
        {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.Int, b.ID)
                };
                return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionConfigureData.GetAllByID, parameter, true);

            
        }

        public void ChonIn(ConfigureData b)
        { 
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.Int, b.ID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigureData.UpdatePrint, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }

        public void BoChonIn(ConfigureData b)
        {
            try
            {
                var parameter = new SqlParameter[]
                {
                    CreateParameter("@ID", SqlDbType.Int, b.ID)
                };
                Execute.DoInsert(clsConstantsFuction.ClsFuctionConfigureData.UpdatePrint2, parameter, true);
            }
            catch (Exception e)
            {
                MessageBox.Show("" + e);
            }
        }
        // các báo cáo

        public DataTable GetAllCauHinhMoi(DateTime Date)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date", SqlDbType.DateTime, Date)
                };
            return Execute.DoStoreGetByID(clsConstantsFuction.ClsFuctionConfigureData.CauHinhMoi, parameter, true);
        }

        public DataTable GetAllConfigureDataDetail()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.ConfigureDataDetail;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllHuyCauHinh()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.HuyCauHinh;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllInChiTietChon()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.InChiTietChon;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllInTich()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.InTich;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllSaukhisuadoi(DateTime Date)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date", SqlDbType.DateTime, Date)
                };
            string sql = clsConstantsFuction.ClsFuctionConfigureData.Saukhisuadoi;
            return Execute.DoStoreGetByID(sql,parameter, true);
        }

        public DataTable GetAllTruockhisuadoi()
        {
            string sql = clsConstantsFuction.ClsFuctionConfigureData.Truockhisuadoi;
            return Execute.DoStoreProcedure(sql, true);
        }

        public DataTable GetAllQTruocvasaukhithaydoicauhinh(DateTime Date)
        {
            var parameter = new SqlParameter[]
                {
                    CreateParameter("@Date", SqlDbType.DateTime, Date)
                };
            string sql = clsConstantsFuction.ClsFuctionConfigureData.QTruocvasaukhithaydoicauhinh;
            return Execute.DoStoreGetByID(sql, parameter, true);
        }
    }
}
